public class Sqrt {
    public int sqrt(int x){
        if(x==1){
            return 1;
        }
        int left=1,right=x;
        int mid=(left+right)/2;
        while (left<=right){
           if(mid<x/mid&&(mid+1)>x/(mid+1)){
               return mid;
           }
           if(mid>x/mid){
               right=mid-1;
           }
           else left=mid+1;
        }return 0;
    }
}
